<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item  label="设备项目代号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equipmentProjectcode">
              <a-input :disabled="true" v-model="model.equipmentProjectcode" placeholder="请输入设备项目代号"  ></a-input>
            </a-form-model-item>
          </a-col>
          
          <a-col :span="12">
            <a-form-model-item label="设备名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入设备名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="地图位置" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lonlat">
              <a-input v-model="model.lonlat" placeholder="请输入地图位置"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="12">
            <a-form-model-item label="设备类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviceType">
              <j-dict-select-tag type="list" v-model="model.deviceType" dictCode="device_type" placeholder="请选择设备类型" />
            </a-form-model-item>
          </a-col>
          
          <a-col :span="12">
            <a-form-model-item label="设备型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviceModel">
              <j-dict-select-tag type="list" v-model="model.deviceModel" dictCode="device_model" placeholder="请选择设备型号" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="设备编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">
              <a-input v-model="model.code" placeholder="请输入设备编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="出厂日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productDate">
              <j-date placeholder="请选择出厂日期" v-model="model.productDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="生产状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionStatus">
              <j-dict-select-tag type="list" v-model="model.productionStatus" dictCode="production_status" placeholder="请选择生产状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="运行状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="runtimeStatus">
              <j-dict-select-tag type="list" v-model="model.runtimeStatus" dictCode="runtime_status" placeholder="请选择运行状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="交付(验收)日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="acceptanceDate">
              <j-date placeholder="请选择交付(验收)日期" v-model="model.acceptanceDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="质保结束日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="warrantyEnddate">
              <j-date placeholder="请选择质保结束日期" v-model="model.warrantyEnddate"  style="width: 100%" />
            </a-form-model-item>
          </a-col> -->
          
          <!-- <a-col :span="12">
            <a-form-model-item label="设备区域" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviceArea">
              <j-select-region v-model="model.deviceArea"  :backRegion="true" :treeOpera="true"> </j-select-region>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="12">
            <a-form-model-item label="制造商" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productor">
              <a-input v-model="model.productor" placeholder="请输入制造商"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="售后服务联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="aftersellContacts">
              <a-input v-model="model.aftersellContacts" placeholder="请输入售后服务联系人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="联系电话及微信号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phoneWechat">
              <a-input v-model="model.phoneWechat" placeholder="请输入联系电话及微信号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="email">
              <a-input v-model="model.email" placeholder="请输入邮箱"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          
          <a-col :span="12">
            <a-form-model-item label="设备项目负责人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="manager">
              <a-input v-model="model.manager" placeholder="请输入设备项目负责人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="用户名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customName">
              <j-dict-select-tag type="list" v-model="model.customName" dictCode="sys_user,username,id" placeholder="请选择用户名称" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="用户地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customAddress">
              <a-input v-model="model.customAddress" placeholder="请输入用户地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="业务联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contracts">
              <j-dict-select-tag type="list" v-model="model.contracts" dictCode="sys_user,username,id" placeholder="请选择业务联系人" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phone">
              <a-input v-model="model.phone" placeholder="请输入联系电话"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="12">
            <a-form-model-item label="PLC品牌与型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="plcBrand">
              <a-input v-model="model.plcBrand" placeholder="请输入PLC品牌与型号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="RDEE品牌与型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeBrand">
              <a-input v-model="model.rdeeBrand" placeholder="请输入RDEE品牌与型号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="RDEE网关型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeRoutetype">
              <a-input v-model="model.rdeeRoutetype" placeholder="请输入RDEE网关型号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="RDEE网关序列号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeRouteserialnumber">
              <a-input v-model="model.rdeeRouteserialnumber" placeholder="请输入RDEE网关序列号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="RDEE网关账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeRouteaccount">
              <a-input v-model="model.rdeeRouteaccount" placeholder="请输入RDEE网关账号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="RDEE网关账号密码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeRoutepassword">
              <a-input v-model="model.rdeeRoutepassword" placeholder="请输入RDEE网关账号密码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="RDEE流量卡号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeFlownumber">
              <a-input v-model="model.rdeeFlownumber" placeholder="请输入RDEE流量卡号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="RDEE ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeId">
              <a-input v-model="model.rdeeId" placeholder="请输入RDEE ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="RDEE IP	" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeIp">
              <a-input v-model="model.rdeeIp" placeholder="请输入RDEE IP	"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="RDEE流量卡到期日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeEnddate">
              <j-date placeholder="请选择RDEE流量卡到期日期" v-model="model.rdeeEnddate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="RDEE MQTT账号密码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rdeeMqtt">
              <a-input v-model="model.rdeeMqtt" placeholder="请输入RDEE MQTT账号密码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea v-model="model.remark" rows="4" placeholder="请输入备注" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import JSelectRegion from '@/components/jeecgbiz/JSelectRegion.vue'

  export default {
    name: 'YksDeviceForm',
    components: {
      JSelectRegion
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        action:'',
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/dev/yksDevice/add",
          edit: "/dev/yksDevice/edit",
          queryById: "/dev/yksDevice/queryById"
        },
        currentEquipmentId:'',
        equipmentProjectcode:''
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.action = "add"
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        if (this.action=="add") {
          this.model.equipmentId = this.currentEquipmentId
          this.model.equipmentProjectcode=this.equipmentProjectcode
        }
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>